package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/store"
	"codejy/structdef"
)

type VariableStrategy struct {
}

func init() {
	RegisterStrategy(&VariableStrategy{})
}
func (n VariableStrategy) getId() int {
	return codeanalysis.Variable
}

func (n VariableStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	v, p := store.GetVariable(threadStore, code)
	if !p {
		//判断父作用域是否存在
		if v1, ok1 := threadStore.VariableStoreMap[threadStore.ParentEnv][code]; ok1 {
			v = v1
		}
	}
	//如果变量返回的是空,那么就返回空值字符串
	if v.Value == "" {
		v.Value = "\"\""
	}
	return v.Value
}
